<?php

namespace app\index\controller;

use app\nav\service\MenuService;
use library\Controller;
use think\facade\Cache;
use throwable;

/**
 * 应用入口
 * Class Index
 * @package app\index\controller
 */
class Index extends Controller
{
    /**
     * 入口跳转链接
     */
    public function index()
    {
        $this->fetch();
    }

    /**
     * 菜单初始化
     * @param MenuService $menuService
     * @throws throwable
     */
    public function menus(MenuService $menuService)
    {
        $obj = Cache::remember('index',
            function (MenuService $menuService) {
                return $menuService->getMenus();
            }
            , 3600);
        $this->success($obj);
    }

    /**
     * 搜索页
     */
    public function search()
    {
        return $this->fetch();
    }

    /**
     * 404
     */
    public function NotFound()
    {
        $this->fetch('exception/404');
    }
}
